package com.mf.controller.basic.webPage;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mf.aspect.debounces.Debounce;
import com.mf.aspect.logApi.LogApi;
import com.mf.entity.dto.basic.webPage.DtoPage;
import com.mf.entity.req.basic.webPage.ReqPage;
import com.mf.entity.req.basic.search.webPage.SearchReqPage;
import com.mf.groups.GroupsAddInterface;
import com.mf.groups.GroupsUpdateInterface;
import com.mf.result.Result;
import com.mf.service.basic.webPage.ServicePage;
import com.mf.utils.UtilConverter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 前端配置页面
 */
@RestController
@RequestMapping("page")
@SaCheckLogin
@Tag(name = "前端配置页面")
@Debounce
public class ControllerPage {
    @Resource
    private ServicePage servicepage;

    @Operation(summary = "分页列表查询")
    @PostMapping("/page")
    @SaCheckPermission("page:search")
    public Result<Page<DtoPage>> findPage(@RequestBody SearchReqPage searchReqPage) {
        return Result.success(servicepage.findPageByParams(searchReqPage));
    }

    @Operation(summary = "列表查询")
    @SaCheckPermission("page:search")
    @PostMapping("/list")
    public Result<List<DtoPage>> list(@RequestBody SearchReqPage searchReqPage) {
        return Result.success(servicepage.findListByParams(searchReqPage));
    }

    @Operation(summary = "保存")
    @SaCheckPermission("page:edit")
    @PostMapping("/save")
    @LogApi(value = "保存页面")
    public Result<Void> save(@Validated(GroupsAddInterface.class) @RequestBody ReqPage reqPage) {
        servicepage.save(UtilConverter.converter(reqPage, DtoPage.class));
        return Result.success();
    }

    @Operation(summary = "修改")
    @SaCheckPermission("page:edit")
    @PostMapping("/update")
    @LogApi(value = "修改页面")
    public Result<Void> update(@Validated(GroupsUpdateInterface.class) @RequestBody ReqPage reqPage) {
        servicepage.updateById(UtilConverter.converter(reqPage, DtoPage.class));
        return Result.success();
    }


    @Operation(summary = "删除")
    @SaCheckPermission("page:delete")
    @GetMapping("/delete/{id}")
    @LogApi(value = "删除页面")
    public Result<Void> delete(@PathVariable("id") Integer id) {
        servicepage.deleteById(id);
        return Result.success();
    }
}
